# 定义接⼝对象类
import requests
from common.get_header_tools import get_req_header


class EmpManagerApi(object):
    # 定义⽅法(接⼝)- 添加员⼯
    @staticmethod
    def add_emp(req_header, req_body):
        resp = requests.post(url="http://ihrm2-test.itheima.net/api/sys/user",
                             headers=req_header, json=req_body)

        return resp

    # 定义⽅法(接⼝)- 查询员⼯
    @staticmethod
    def query_emp(emp_id, req_header):
        resp = requests.get(url="http://ihrm2-test.itheima.net/api/sys/user/" +
                                emp_id,
                            headers=req_header)

        return resp

    # 定义⽅法(接⼝)- 修改员⼯
    @staticmethod
    def modify_emp(emp_id, req_header, req_body):
        resp = requests.put(url="http://ihrm2-test.itheima.net/api/sys/user/" +
                                emp_id,
                            headers=req_header, json=req_body)

        return resp

    # 定义⽅法(接⼝)- 删除员⼯
    @staticmethod
    def delete_emp(emp_id, req_header):
        return requests.delete(url="http://ihrm2-test.itheima.net/api/sys/user/" +
                                   emp_id, headers=req_header)


# 必须⾃测
if __name__ == '__main__':
    # 准备请求头
    req_header = get_req_header()
    # 准备请求体
    req_body = {
        "username": "user8",
        "mobile": "13947889890",
        "workNumber": "9527890aa"
    }
    # 类名.⽅法 --- 调⽤静态⽅法
    resp = EmpManagerApi.add_emp(req_header, req_body)
    print(resp.json())
